package com.tanhua.server.Controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //评论列表
    @GetMapping
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   String movementId){
        PageResult vo = commentService.findComments(movementId,page,pageSize);
        return ResponseEntity.ok(vo);
    }

    //发布评论
    @PostMapping
    public ResponseEntity comments(@RequestBody Map map){

        String movementId =  map.get("movementId").toString();
        String comment = map.get("comment").toString();
        //调用service
        commentService.saveComment(comment,movementId);
        //返回结果
        return ResponseEntity.ok(null);
    }
}
